package test.peaw.ccb.controller.annotation;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class JsonController {
	
	@RequestMapping("/getJson")
	public ModelAndView getJson(String filename) {
		ModelAndView mv = new ModelAndView("huidanmingxi");
		filename = "201";
		try {
			List<String> liststr = FileUtils.readLines(new File("D:/ccb/" + filename + ".txt"), "GBK");
			List<Map<String,String>> list = new ArrayList<Map<String,String>>();
			for (String string : liststr) {
				String[] strs = string.split("~");
				Map<String,String> map = new HashMap<String, String>();
				for (int i = 0; i < strs.length; i++) {
					switch (i) {
					case 0: //交易时间
						map.put(i + "", strs[i]);
						break;
					case 1: //借方发生额
						map.put(i + "", strs[i]);
						break;
					case 2: //贷方发生额
						map.put(i + "", strs[i]);
						break;
					case 3: //余额
						map.put(i + "", strs[i]);
						break;
					case 4: //对方户名
						map.put(i + "", strs[i]);
						break;
					case 5: //对方账号
						map.put(i + "", strs[i]);
						break;
					case 6: //对方开户机构
						map.put(i + "", strs[i]);
						break;
					case 7: //记账日期
						map.put(i + "", strs[i]);
						break;
					case 8: //摘要
						map.put(i + "", strs[i]);
						break;
					case 9: //备注
						map.put(i + "", strs[i]);
						break;
					case 10: //账户明细编号交易流水号
						map.put(i + "", strs[i]);
						break;
					case 11: //企业流水号
						map.put(i + "", strs[i]);
						break;
					case 12: //凭证种类
						map.put(i + "", strs[i]);
						break;
					case 13: //凭证号码
						map.put(i + "", strs[i]);
						break;

					default:
						break;
					}
					map.put(i + "", strs[i]);
				}
				list.add(map);
			}
			Map<String,List<Map<String,String>>> map = new HashMap<String, List<Map<String,String>>>();
			map.put("list", list);
			mv = new ModelAndView("huidanmingxi","map",map);
			System.out.println(mv);
			return mv;
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return mv;
	}
	
	
	public static void main(String[] args) throws Exception {
		String filename = "201";
		List<String> liststr = FileUtils.readLines(new File("D:/ccb/" + filename + ".txt"), "GBK");
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		for (String string : liststr) {
			String[] strs = string.split("~");
			Map<String,String> map = new HashMap<String, String>();
			for (int i = 0; i < strs.length; i++) {
				map.put(i + "", strs[i]);
			}
			list.add(map);
		}
		
		for (Map<String, String> map : list) {
			System.out.println(map.size());
		}
	}
	
}
